package com.epam.iunna.bookshop.controller.actions;

import java.sql.SQLException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.epam.iunna.bookshop.controller.application.Constants;
import com.epam.iunna.bookshop.controller.utils.dispatch.ActionInt;
import com.epam.iunna.bookshop.model.Item;
import com.epam.iunna.bookshop.model.ItemDao;

public class BooksList implements ActionInt{

	@Override
	public String perform(HttpServletRequest request,
			HttpServletResponse response) {
	    ItemDao itemDao = new ItemDao();
	    List<Item> itemsList = null;
	    try {
            itemsList = itemDao.getAll();
        } catch (SQLException e) {
            //LOG
            e.printStackTrace();
            return Constants.FATAL_ERROR_PAGE_PATH;
        }
	    
	    request.setAttribute("itemsList", itemsList);
	    
		return "/booksList.jsp";
	}

}
